package com.masterclient.app.modules.order.adapter;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.eoner.baselib.utils.toast.ToastUtil;
import com.eoner.baselibrary.bean.goods.ProductPromotionMessage;
import com.eoner.baselibrary.bean.goods.ProductPromotionProperty;
import com.eoner.baselibrary.bean.order.ConfirmOrderData;
import com.eoner.baselibrary.bean.order.ConfirmOrderOrder;
import com.eoner.baselibrary.bean.order.InvoiceBean;
import com.eoner.baselibrary.bean.order.OrderProductMessage;
import com.eoner.baselibrary.utils.GlideUtil;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.Utils;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.masterclient.app.R;
import com.masterclient.app.base.MainViewHolder;
import com.masterclient.app.modules.order.InvoiceActivity;
import com.masterclient.app.widget.PriceIntegralLayout;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SubmitOrderProductsAdapter extends DelegateAdapter.Adapter<MainViewHolder> {

    Activity mContext;
    private LayoutHelper mLayoutHelper;
    private VirtualLayoutManager.LayoutParams mLayoutParams;
    private int mCount;
    ConfirmOrderData data;
    List<ConfirmOrderOrder> orders;
    OnCouponClick onCouponClick;
    private int freightType = 0;
    private String freightTxt = "请选择";

    private LinearLayout ll_shop_container;
    private String saleType;

    private Map<String, InvoiceBean> map = new HashMap<>();
    private List<String> product_id = new ArrayList<>();
    private SelectFreightListener selectFreightListener;

    public interface OnCouponClick {
        void OnItemClick();
    }

    public OnCouponClick getOnAddressClick() {
        return onCouponClick;
    }

    public void setOnCouponClick(OnCouponClick onCouponClick) {
        this.onCouponClick = onCouponClick;
    }

    public void setOnSelectFreightListener(SelectFreightListener selectFreightListener) {
        this.selectFreightListener = selectFreightListener;
    }

    public SubmitOrderProductsAdapter(Activity context, LayoutHelper layoutHelper, int count) {
        this(context, layoutHelper, count, null, null, null,"");
    }

    public SubmitOrderProductsAdapter(Activity context, LayoutHelper layoutHelper, int count, @NonNull VirtualLayoutManager.LayoutParams layoutParams, ConfirmOrderData data, List<ConfirmOrderOrder> orders,String saleType) {
        this.mContext = context;
        this.mLayoutHelper = layoutHelper;
        this.mCount = count;
        this.mLayoutParams = layoutParams;
        this.data = data;
        this.orders = orders;
        this.saleType = saleType;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }

    @Override
    protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {

    }

    @Override
    public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }

    @Override
    public void onBindViewHolder(MainViewHolder holder, int position) {
        if (mLayoutParams != null) {
            holder.itemView.setLayoutParams(
                    new VirtualLayoutManager.LayoutParams(mLayoutParams));
        }

        if (data != null && data.getOrders() != null && data.getOrders().size() > 0) {
            ll_shop_container = holder.itemView.findViewById(R.id.ll_shop_container);
            ll_shop_container.removeAllViews();
            for (int i = 0; i < orders.size(); i++) {
                //店铺信息
                ConfirmOrderOrder confirmOrderOrder = orders.get(i);
                View viewShop = View.inflate(mContext, R.layout.view_confirm_shop, null);
                View viewBottom = viewShop.findViewById(R.id.view_bottom);
                View viewOtherBottom = viewShop.findViewById(R.id.view_bottom_other);

//                View viewPayFreight = viewShop.findViewById(R.id.view_pay_freight);
//                TextView tv_freight_type = viewShop.findViewById(R.id.tv_freight_type);
                TextView tv_goods_num = viewShop.findViewById(R.id.tv_goods_num);
                TextView tv_freight = viewShop.findViewById(R.id.tv_freight);
                RelativeLayout viewFreight = viewShop.findViewById(R.id.view_freight);
                TextView tv_shop_freight = viewShop.findViewById(R.id.tv_shop_freight);
                TextView tv_shop_freight_name = viewShop.findViewById(R.id.tv_shop_freight_name);
                View view_tag_msg = viewShop.findViewById(R.id.view_tag_msg);
                EditText et_buyer_message = viewShop.findViewById(R.id.et_buyer_message);
                TextView tv_shop_gos_num = viewShop.findViewById(R.id.tv_shop_goods_num);
                TextView tv_shop_price = viewShop.findViewById(R.id.tv_shop_price);
                Utils.setDin(tv_shop_price, mContext);
                LinearLayout ll_goods_container = viewShop.findViewById(R.id.ll_goods_container);
                RelativeLayout rl_invoice = viewShop.findViewById(R.id.rl_invoice);
                CheckBox checkBox_invoice = viewShop.findViewById(R.id.checkBox_invoice);
                TextView tvInvoiceMsg = viewShop.findViewById(R.id.tv_invocie_msg);
                TextView tvInvoiceTitle = viewShop.findViewById(R.id.tv_invocie_title);
                TextView tv_shop_name = viewShop.findViewById(R.id.tv_shop_name);
                RelativeLayout rl_clear = viewShop.findViewById(R.id.rl_clear);
                TextView cross_border_flag_view = viewShop.findViewById(R.id.cross_border_flag_view);

                if ("6".equals(saleType)){
                    //提货商品
                    viewBottom.setVisibility(View.GONE);
                    viewOtherBottom.setVisibility(View.VISIBLE);
//                    tv_freight_type.setText(freightTxt);
//                    if (freightTxt.equals("请选择")){
//                        tv_freight_type.setTextColor(Color.parseColor("#999faa"));
//                    }else {
//                        tv_freight_type.setTextColor(Color.parseColor("#141922"));
//                    }
                    tv_goods_num.setText(confirmOrderOrder.getNum());
                    tv_freight.setText(String.format("¥%s", confirmOrderOrder.getFreight().getPrice()));
//                    viewPayFreight.setOnClickListener(v -> {
//                        FreightSelectDialog freightSelectDialog = new FreightSelectDialog(mContext, freightType, (freightType, txt) -> {
//                            this.freightType = freightType;
//                            freightTxt = txt;
//                            tv_freight_type.setText(txt);
//                            tv_freight_type.setTextColor(Color.parseColor("#141922"));
//                            selectFreightListener.onSelectFreight(freightType);
//                        });
//                        freightSelectDialog.show();
//                    });
                }else {
                    //其他商品
                    viewBottom.setVisibility(View.VISIBLE);
                    viewOtherBottom.setVisibility(View.GONE);
                }

                if ("2".equals(confirmOrderOrder.getSeller().getSeller_type())) {
                    cross_border_flag_view.setVisibility(View.VISIBLE);
                } else {
                    cross_border_flag_view.setVisibility(View.GONE);
                }

                tv_shop_name.setText(!TextUtils.isEmpty(saleType)&&"4".equals(saleType)?"商品信息":confirmOrderOrder.getSeller().getStore_name());
                if (null != confirmOrderOrder.getSeller().getInvoiceBean()) {
                    InvoiceBean invoiceBean = confirmOrderOrder.getSeller().getInvoiceBean();
                    checkBox_invoice.setClickable(true);
                    checkBox_invoice.setChecked(true);
                    String invoiceMsg = "";
                    String type_name = invoiceBean.getName_type();
                    String vat_type = invoiceBean.getVat_type();
                    String fapiao_type = invoiceBean.getType();
                    if ("1".equals(type_name) && "1".equals(fapiao_type)) {//电子个人
                        invoiceMsg = "个人电子发票";
                    } else if ("1".equals(type_name) && "2".equals(fapiao_type)) {//纸质个人
                        invoiceMsg = "个人纸质发票";
                    } else if ("2".equals(type_name) && "1".equals(fapiao_type)) {//电子公司
                        invoiceMsg = "公司电子发票";
                    } else if ("2".equals(type_name) && "2".equals(fapiao_type)) {//纸质公司
                        if ("1".equals(vat_type)) {      //专用
                            invoiceMsg = "公司纸质专用发票";
                        } else if ("2".equals(vat_type)) {//普通
                            invoiceMsg = "公司纸质普通发票";
                        }
                    }
                    tvInvoiceMsg.setText(invoiceMsg);
                    tvInvoiceTitle.setText(invoiceBean.getName());
                } else {
                    checkBox_invoice.setClickable(false);
                }

                if (confirmOrderOrder.getSeller().getInvoice_type() != null && confirmOrderOrder.getSeller().getInvoice_type().size() > 0) {
                    rl_invoice.setVisibility(View.VISIBLE);
                } else {
                    rl_invoice.setVisibility(View.GONE);
                }

                checkBox_invoice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (!isChecked) {
                            checkBox_invoice.setClickable(false);
                            tvInvoiceMsg.setText("我要开发票");
                            map.remove(confirmOrderOrder.getSeller().getSeller_id());
                        }
                    }
                });

                int finalI = i;
                rl_invoice.setOnClickListener((View v) -> {
                    Intent intent = new Intent(mContext, InvoiceActivity.class);
                    if (confirmOrderOrder.getSeller().getInvoice_type() != null && confirmOrderOrder.getSeller().getInvoice_type().size() > 0) {
                        intent.putExtra("invoice_type", (Serializable) confirmOrderOrder.getSeller().getInvoice_type());
                        intent.putExtra("url", (Serializable) data.getInstructions().getInvoice_introduce());

                        Bundle bundle = new Bundle();
                        bundle.putString("shop_id", confirmOrderOrder.getSeller().getSeller_id());
                        bundle.putString("position", String.valueOf(finalI));
                        bundle.putString("label", data.getInvoice_label());
                        bundle.putString("url", data.getInstructions().getInvoice_introduce());
                        bundle.putSerializable("invoice", map.get(confirmOrderOrder.getSeller().getSeller_id()));
                        intent.putExtras(bundle);
                        mContext.startActivityForResult(intent, 101);
                    } else {
                        ToastUtil.showToast("特殊商品不支持开发票");
                    }
                });

                if ("0".equals(data.getIs_hidden_remark())) {
                    view_tag_msg.setVisibility(View.VISIBLE);
                } else {
                    view_tag_msg.setVisibility(View.GONE);
                }

                if ("0".equals(data.getIs_hidden_address())) {
                    viewFreight.setVisibility(View.VISIBLE);
                } else {
                    viewFreight.setVisibility(View.GONE);
                }

                et_buyer_message.setText(confirmOrderOrder.getSeller().getRemark());
                et_buyer_message.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        confirmOrderOrder.getSeller().setRemark(s.toString());
                        if (TextUtils.isEmpty(s.toString())) {
                            rl_clear.setVisibility(View.GONE);
                        } else {
                            rl_clear.setVisibility(View.VISIBLE);
                        }
                    }

                    @Override
                    public void afterTextChanged(Editable s) {

                    }
                });

                rl_clear.setOnClickListener(v -> {
                    et_buyer_message.setText("");
                    confirmOrderOrder.getSeller().setRemark("");
                });
                tv_shop_freight_name.setText(confirmOrderOrder.getFreight().getTip());
                tv_shop_freight.setText("¥" + confirmOrderOrder.getFreight().getPrice());
                tv_shop_gos_num.setText(confirmOrderOrder.getNum());
                tv_shop_price.setText("¥ " + confirmOrderOrder.getPrices().getPay_price());

                //商品信息
                ll_goods_container.removeAllViews();
                for (int j = 0;j < confirmOrderOrder.getProducts().size();j++) {
                    OrderProductMessage item = confirmOrderOrder.getProducts().get(j);
                    product_id.add(item.getProduct_main_id());
                    View viewGos = View.inflate(mContext, R.layout.view_confirm_goods_view, null);

                    ImageView ivGood = viewGos.findViewById(R.id.iv_good);
                    TextView tv_title = viewGos.findViewById(R.id.tv_title);
                    TextView tv_skus = viewGos.findViewById(R.id.tv_skus);
                    TextView tv_pick_good_num = viewGos.findViewById(R.id.tv_pick_good_num);
                    LinearLayout llSkuContainer = viewGos.findViewById(R.id.ll_sku_container);
                    PriceIntegralLayout ll_price = viewGos.findViewById(R.id.ll_price);
                    TextView tv_jb = viewGos.findViewById(R.id.tv_jb);
//                    Utils.setDin(tv_price, mContext);
                    TextView tv_gos_num = viewGos.findViewById(R.id.tv_gos_num);
                    TextView tv_delivery = viewGos.findViewById(R.id.tv_delivery);
                    TextView point_flag = viewGos.findViewById(R.id.point_flag);
                    TextView new_share_tag = viewGos.findViewById(R.id.new_share_tag);
                    ImageView ivActivity = viewGos.findViewById(R.id.iv_activity);
                    View bottomLine = viewGos.findViewById(R.id.bottom_line);

                    if (j == confirmOrderOrder.getProducts().size()-1){
                        bottomLine.setVisibility(View.GONE);
                    }else {
                        bottomLine.setVisibility(View.VISIBLE);
                    }
                    double ratio = 1;
                    if (!TextUtils.isEmpty(item.getImage_width())){
                        ratio = ScreenUtils.dp2px(107)/Double.parseDouble(item.getImage_width());
                    }
                    if (item.getIcon_info() != null && !TextUtils.isEmpty(item.getIcon_info().iconHeight)) {
                        int leftMargin = (int) (Integer.parseInt(item.getIcon_info().iconLeftMargin)*ratio);
                        int topMargin = (int) (Integer.parseInt(item.getIcon_info().iconTopMargin)*ratio);
                        int bottomMargin = (int) (Integer.parseInt(item.getIcon_info().iconBottomMargin)*ratio);
                        ViewTransformUtil.glideImageView(mContext,item.getIcon_info().iconImage,ivActivity,R.mipmap.defaults);
                        ivActivity.setVisibility(View.VISIBLE);
                        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ivActivity.getLayoutParams();
                        params.height = (int) (Integer.valueOf(item.getIcon_info().iconHeight)*ratio);
                        params.width = (int) (Integer.valueOf(item.getIcon_info().iconWidth)*ratio);
                        params.addRule(RelativeLayout.ALIGN_BOTTOM,0);
                        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT,0);
                        params.setMargins(0, 0, 0, 0);
                        switch (item.getIcon_info().iconMarginType) {
                            case "1":
                                params.addRule(RelativeLayout.ALIGN_BOTTOM,R.id.iv_good);
                                params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                                params.setMargins(leftMargin, topMargin, 0, bottomMargin);
                                break;
                            case "2":
                                params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                                params.setMargins(leftMargin, topMargin, 0, bottomMargin);
                                break;
                        }
                        ivActivity.setLayoutParams(params);
                    }else {
                        ivActivity.setVisibility(View.GONE);
                    }

                    if (!item.getIs_delivery()) {
                        tv_delivery.setVisibility(View.VISIBLE);
                        tv_delivery.setText(item.getDelivery_desc());
                    } else {
                        tv_delivery.setVisibility(View.INVISIBLE);
                    }

                    GlideUtil.displayImage(mContext, item.getImage(), ivGood, R.mipmap.defaults, 107, 107);
                    tv_title.setText(item.getTitle());
                    TextView priceTv = viewGos.findViewById(R.id.tag_price_vip);
                    if (!TextUtils.isEmpty(saleType)&&"4".equals(saleType)){
                        priceTv.setText("拿货价");
                        priceTv.setVisibility(View.VISIBLE);
                        tv_shop_price.setTextColor(Color.parseColor("#FF5000"));
                    }else {
                        priceTv.setText("会员价");
                        priceTv.setVisibility(item.isShow_vip_price()?View.VISIBLE:View.GONE);
                    }
                    if (item.isShow_vip_price()){
                        ll_price.setData("",item.getVip_price());
                    }else {
                        ll_price.setData(item.getIntegral_price(), item.getPrice());
                    }
//                    Utils.set_price_style(mContext,tv_price,12,item.getIntegral_price(),item.getPrice());

                    if ("2".equals(item.getProduct_type())) {
//                        tv_price.setText(item.getIntegral_price());
//                        tv_jb.setVisibility(View.VISIBLE);
                        point_flag.setVisibility(View.VISIBLE);
                    } else {
//                        Utils.set_goodsdetail_price_style1(tv_price, "¥ " + item.getPrice());
                        point_flag.setVisibility(View.GONE);
//                        tv_jb.setVisibility(View.GONE);
                    }

                    //限购
                    if ("2".equals(item.getActivity_flag())) {
                        ll_price.setData("0", item.getPrice());
                        new_share_tag.setVisibility(View.VISIBLE);
                        if ("0".equals(item.getActivity_new_user().getLimit_num())) {
                            new_share_tag.setText(item.getActivity_new_user().getLabel_name());
                        } else {
                            new_share_tag.setText("限购" + item.getActivity_new_user().getLimit_num() + "件");
                        }
                    } else {
                        new_share_tag.setVisibility(View.GONE);
                    }

                    //sku显示(分普通商品显示和话费充值商品显示)
                    if ("1".equals(item.getBiz_type())) {
                        llSkuContainer.setVisibility(View.VISIBLE);
                        tv_skus.setVisibility(View.GONE);
                        List<ProductPromotionProperty> listProperty = item.getProperties();
                        if (listProperty != null && listProperty.size() > 0) {
                            llSkuContainer.setVisibility(View.VISIBLE);
                            llSkuContainer.removeAllViews();
                            for (ProductPromotionProperty propertyBean: listProperty) {
                                View viewSku = View.inflate(mContext, R.layout.item_sku_info, null);
                                TextView tvSkus = viewSku.findViewById(R.id.tv_skus);
                                tvSkus.setText(propertyBean.getAttribute_label() + ":" + propertyBean.getAlias_name());
                                llSkuContainer.addView(viewSku);
                            }
                        } else {
                            llSkuContainer.setVisibility(View.GONE);
                        }
                    } else {
                        llSkuContainer.setVisibility(View.GONE);
                        tv_skus.setVisibility(View.VISIBLE);
                        List<ProductPromotionProperty> listProperty = item.getProperties();
                        StringBuilder sku = new StringBuilder();
                        if (listProperty != null) {
                            sku.append("规格：");
                            for (ProductPromotionProperty property : listProperty) {
                                sku.append(" ")
                                        .append(property.getAlias_name())
                                        .append(" ");
                            }
                        }
                        tv_skus.setText(sku);
                    }
                    tv_gos_num.setText("x" + item.getNum());


                    //赠品列表
                    List<ProductPromotionMessage> productMessageList = item.getPromotions();
                    View cross_border_layout = viewGos.findViewById(R.id.cross_border_layout);
                    if (productMessageList != null && productMessageList.size() > 0) {
                        cross_border_layout.setVisibility(View.VISIBLE);
                        LinearLayout ll_shop_present_container = (LinearLayout) viewGos.findViewById(R.id.ll_shop_present_container);
                        ll_shop_present_container.removeAllViews();
                        for (ProductPromotionMessage promotionProductMessage : productMessageList) {
                            View view_present_goods = View.inflate(mContext, R.layout.item_present, null);
                            ImageView ivPresentGood = view_present_goods.findViewById(R.id.iv_good);
                            TextView ivPresentTitle = view_present_goods.findViewById(R.id.tv_title);
                            TextView ivPresentSkus = view_present_goods.findViewById(R.id.tv_skus);
                            TextView ivPresentPrice = view_present_goods.findViewById(R.id.tv_price);
                            TextView ivPresentNum = view_present_goods.findViewById(R.id.tv_num);

                            ivPresentTitle.setText(promotionProductMessage.getName());
                            ivPresentNum.setText("x" + promotionProductMessage.getNum());

                            List<ProductPromotionProperty> listProperty = item.getProperties();
                            List<ProductPromotionProperty> promotionProperty = promotionProductMessage.getProperties();
                            StringBuilder promotionSku = new StringBuilder();
                            if (listProperty != null) {
                                promotionSku.append("规格：");
                                for (ProductPromotionProperty property : promotionProperty) {
                                    promotionSku.append("“")
                                            .append(property.getAlias_name())
                                            .append("” ");
                                }
                            }
                            ivPresentSkus.setText(promotionSku);
                            ivPresentPrice.setText("¥" + promotionProductMessage.getPrice());
                            ivPresentPrice.setVisibility(View.GONE);
                            GlideUtil.displayRoundImage(mContext, promotionProductMessage.getImage(), ivPresentGood, 7, R.mipmap.defaults);
                            ll_shop_present_container.addView(view_present_goods);
                        }
                    } else {
                        cross_border_layout.setVisibility(View.GONE);
                    }

                    if ("6".equals(saleType)){
                        //提货商品
                        tv_pick_good_num.setVisibility(View.VISIBLE);
                        tv_pick_good_num.setText("提货数量 "+item.getNum());

                        llSkuContainer.setVisibility(View.GONE);
                        ll_price.setVisibility(View.GONE);
                        tv_gos_num.setVisibility(View.GONE);
                        tv_delivery.setVisibility(View.GONE);
                        point_flag.setVisibility(View.GONE);
                        new_share_tag.setVisibility(View.GONE);
                        ivActivity.setVisibility(View.GONE);
                    }else {
                        tv_pick_good_num.setVisibility(View.GONE);
                    }
                    ll_goods_container.addView(viewGos);
                }
                ll_shop_container.addView(viewShop);
            }
        }
    }

    public void refreshInvoice(Intent intent) {
        int position = Integer.valueOf(intent.getStringExtra("position"));
        InvoiceBean invoiceBean = (InvoiceBean) intent.getSerializableExtra("invoice");
        orders.get(position).getSeller().setInvoiceBean(invoiceBean);
        map.put(intent.getStringExtra("shop_id"), invoiceBean);
        View view = ll_shop_container.getChildAt(Integer.valueOf(position));
        CheckBox checkBox_invoice = view.findViewById(R.id.checkBox_invoice);
        checkBox_invoice.setClickable(true);
        checkBox_invoice.setChecked(true);
        TextView tvInvoiceMsg = view.findViewById(R.id.tv_invocie_msg);
        TextView tvInvoiceTitle = view.findViewById(R.id.tv_invocie_title);
        String invoiceMsg = "";
        String type_name = invoiceBean.getName_type();
        String vat_type = invoiceBean.getVat_type();
        String fapiao_type = invoiceBean.getType();
        if ("1".equals(type_name) && "1".equals(fapiao_type)) {//电子个人
            invoiceMsg = "个人电子发票";
        } else if ("1".equals(type_name) && "2".equals(fapiao_type)) {//纸质个人
            invoiceMsg = "个人纸质发票";
        } else if ("2".equals(type_name) && "1".equals(fapiao_type)) {//电子公司
            invoiceMsg = "公司电子发票";
        } else if ("2".equals(type_name) && "2".equals(fapiao_type)) {//纸质公司
            if ("1".equals(vat_type)) {      //专用
                invoiceMsg = "公司纸质专用发票";
            } else if ("2".equals(vat_type)) {//普通
                invoiceMsg = "公司纸质普通发票";
            }
        }
        tvInvoiceMsg.setText(invoiceMsg);
        tvInvoiceTitle.setText(invoiceBean.getName());
    }

    public void refreshProductInfo(List<ConfirmOrderOrder> orders) {
        for (int i = 0; i < orders.size(); i++) {
            for (int j = 0; j < this.orders.size(); j++) {
                if (orders.get(i).getSeller().getSeller_id().equals(this.orders.get(j).getSeller().getSeller_id())) {
                    this.orders.get(j).getPrices().setPay_price(orders.get(i).getPrices().getPay_price());
                    this.orders.get(j).getFreight().setPrice(orders.get(i).getFreight().getPrice());
                    this.orders.get(j).getFreight().setTip(orders.get(i).getFreight().getTip());

                    for (int k = 0; k < orders.get(i).getProducts().size(); k++) {
                        for (int h = 0; h < this.orders.get(j).getProducts().size(); h++) {
                            if (orders.get(i).getProducts().get(k).getProduct_id().equals(this.orders.get(j).getProducts().get(h).getProduct_id())) {
                                this.orders.get(j).getProducts().get(h).setIs_delivery(orders.get(i).getProducts().get(k).getIs_delivery());
                                this.orders.get(j).getProducts().get(h).setDelivery_desc(orders.get(i).getProducts().get(k).getDelivery_desc());
                            }
                        }
                    }
                }
            }
        }
        notifyDataSetChanged();
    }

    public interface SelectFreightListener {
        void onSelectFreight(int freightType);
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    @Override
    public int getItemViewType(int position) {
        return 8;
    }
}
